package com.zhl.mapreduce.wordcount;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;


/*
    keyin , map阶段输入的key类型 : LongWritable
    valuein, map阶段输入的value类型 : Text
    keyout, map阶段输出的key类型 : Text
    valueout, map阶段输出的value类型 : IntWritable
*/
public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable>{

    private Text outk = new Text();
    private IntWritable outv = new IntWritable(1);

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //1、先获取一行
        // atguigu  atguigu
        String line = value.toString();

        //2、切割
        //atguigu
        //atguigu
        String[] words = line.split(" ");

        //3、循环写出
        for (String word : words) {
            //封装

            outk.set(word);
            //写出
            context.write(outk, outv);

        }

    }


}
